package com.ts.main.admin.service;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ts.main.admin.dto.MiniUserAddressDto;
import com.ts.main.admin.dto.MiniUserAddressSearchPageDto;
import com.ts.main.admin.entity.UserAddressEntity;
import com.ts.main.admin.exception.RPage;
import com.ts.main.admin.mapper.UserAddressMapper;
import com.ts.main.admin.vo.AdminRoleVo;
import com.ts.main.admin.vo.MiniUserAddressVo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author lk
* @description 针对表【t_user_address(用户收货地址表)】的数据库操作Service实现
* @createDate 2025-06-09 00:56:13
*/
@AllArgsConstructor
@Service
public class UserAddressServiceImpl extends ServiceImpl<UserAddressMapper, UserAddressEntity>{

    public RPage<List<MiniUserAddressVo>> getMiniUserAddressPage(MiniUserAddressSearchPageDto dto) {
        Page<Object> page = PageHelper.startPage(dto.getPage(), dto.getLimit());
        List<MiniUserAddressVo> list = baseMapper.getMiniUserAddressPage(dto);
        return RPage.ok(list, dto.getPage(), dto.getLimit(), page.getTotal());
    }

    public MiniUserAddressVo getMiniUserAddressDetails(Integer userAddressId) {
        return baseMapper.getMiniUserAddressDetails(userAddressId);
    }

    public MiniUserAddressDto saveMiniUserAddress(MiniUserAddressDto dto) {
        saveMiniUserAddress(BeanUtil.copyProperties(dto, MiniUserAddressDto.class));
        return dto;
    }

    public Boolean updateMiniUserAddress(MiniUserAddressDto dto) {
        return updateMiniUserAddress(BeanUtil.copyProperties(dto, MiniUserAddressDto.class));
    }

    public Boolean deleteMiniUserAddress(Integer userAddressId) {
        LambdaUpdateWrapper<UserAddressEntity> wrapper = new LambdaUpdateWrapper<>();
        wrapper
                .eq(UserAddressEntity::getUserAddressId, userAddressId)
                .set(UserAddressEntity::getIsDeleted,true);
        return update(wrapper);
    }

}




